package org.zuel.boot.demo.controller;

import org.zuel.boot.demo.entity.Student;
import org.zuel.boot.demo.entity.SysUser;
import org.zuel.boot.demo.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.zuel.boot.demo.service.impl.SessionService;
import org.zuel.boot.demo.web.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 *  控制器
 *
 * @author ikun
 */
@Api(tags = "管理")
@RestController
@RequestMapping("/zuel")
public class StudentController{
    @Autowired
    private SessionService sessionService;
    private IStudentService studentService;

    @Autowired
    public StudentController(IStudentService studentService){
        this.studentService = studentService;
    }

    @ApiOperation("查询列表")
    @GetMapping("/student/list")
    public PageResult<Student> list(HttpServletRequest request) {
        PageParam<Student> pageParam = new PageParam<>(request);
        return studentService.list(pageParam);
    }

    @ApiOperation("查询单个")
    @GetMapping("/student/get/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return studentService.read(id);
    }



    @ApiOperation("添加")
    @PostMapping("/student/add")
    public JsonResult add(@RequestBody Student model) {
    return studentService.add(model);
    }

    @ApiOperation("修改")
    @PostMapping("/student/update")
    public JsonResult update(@RequestBody Student model) {
    return studentService.update(model);
    }

    @ApiOperation("删除")
    @GetMapping("/student/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return studentService.delete(ids);
    }

}